﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        //确认提交
        private void button1_Click(object sender, EventArgs e)  
        {
            string insertuid =  textBox1.Text;
            string inserpwd = textBox2.Text; 
            string repwd = textBox3.Text;
            bool hasuser = !string.IsNullOrEmpty(insertuid);
            bool haspwd = !string.IsNullOrEmpty(inserpwd);

            var sql = string.Format("select COUNT(*) from Login where Name = '{0}'", insertuid);
            string comString = "server =PC-202001311751\\MYSQLSERVER; uid =yun0823;pwd =jxy130452;database =WinformText";
            SqlConnection sqlConnection = new SqlConnection(comString);
            SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
            sqlConnection.Open();
            int i = Convert.ToInt32(sqlCommand.ExecuteScalar());
            sqlConnection.Close();
            if (i > 0)
            {
                MessageBox.Show("已存在该用户名");
            }
            else
            {
               
                    if (!hasuser)
                    {
                        MessageBox.Show("用户名不能为空");
                    }
                    else
                    {
                        if (!haspwd)
                        {
                            MessageBox.Show("密码不能为空");
                        }
                        else if(inserpwd != repwd && !haspwd)
                        {
                            MessageBox.Show("密码不相同");
                        }
                    else
                    {
                        var str = string.Format("insert into Login (Name,LPassword) values ('{0}','{1}')", insertuid, inserpwd);
                        DbHelper.GetdataTable(str);
                        MessageBox.Show("注册成功");
                    }
                 }
                    

                
            }


            

           
          







           


        }


        //取消
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }



     
        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }




    }
}
